__device__ void processVotes();

__global__ void processAccum(centroid_list* d_possCentroids)
{	
	processVotes();
}

__device__ void processVotes()
{
	int index = blockIdx.x * blockDim.x + threadIdx.x, i = 0;
	double distance = 0.0;
	point_3d_t centroidPt, currCentroidPt;
	bool notFound = true;
	
	do
	{
	//	printf("thread number %d ...  x: %.6f, y: %.6f, z: %.6f\n", index,d_possCentroids[index].centroid.x,d_possCentroids[index].centroid.y,d_possCentroids[index].centroid.z);
		//don't revote
		if(i != index)
		{
			if((int)d_possCentroids[index].centroid.x == (int)d_possCentroids[i].centroid.x &&
			   (int)d_possCentroids[index].centroid.y == (int)d_possCentroids[i].centroid.y &&
			   (int)d_possCentroids[index].centroid.z == (int)d_possCentroids[i].centroid.z)
			{
	//			printf("thread number %d voting for centroid # %d .... x: %.6f, y: %.6f, z: %.6f\n", index, i,d_possCentroids[index].centroid.x,d_possCentroids[index].centroid.y,d_possCentroids[index].centroid.z);
				atomicAdd(&d_possCentroids[i].votes, 1);//++;
			//	printf("thread ... %d ..... votes ...... %d\n", index, d_possCentroids[i].votes);
				notFound = false;

				// correct the edge pixels centroid vote to match
				// the centroid just matched
				d_voters[index * DATA_POINTS].centroidIndex = i;
				d_voters[index * DATA_POINTS + 1].centroidIndex = i;
				d_voters[index * DATA_POINTS + 2].centroidIndex = i;
				d_voters[index * DATA_POINTS + 3].centroidIndex = i;
			}
		}
		else
			notFound = false;
			
		i++;
		
	}while(notFound && i < EVIDENCE_TRSH);
	
//	printf("thread id:  %d, vote count: %d\n", index, d_possCentroids[index].votes);
	//printf("thread number %d voting for centroid x: %.6f, y: %.6f, z: %.6f..... votes%d\n", index,  d_possCentroids[i].centroid.x,d_possCentroids[i].centroid.y,d_possCentroids[i].centroid.z, d_possCentroids[i].votes);
//	printf("index %d ... x: %f, y: %f, z: %f, ..... votes: %d\n", index, d_possCentroids[index].meanCentroid.x, d_possCentroids[index].meanCentroid.y, d_possCentroids[index].meanCentroid.z, d_possCentroids[index].votes);
	
}


